package com.shizhanzhe.zxbapp.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.UserBean;
import com.shizhanzhe.zxbapp.url.Path;
import com.shizhanzhe.zxbapp.utils.OkHttpDownloadJsonUtil;
import com.shizhanzhe.zxbapp.utils.Util;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by YJ on 2018/11/6.
 */
public class AdvertisementPopupWindow extends PopupWindow {
    private View contextView;

    public void setListener(onclick  listener) {
        onclickListen = listener;
    }
    public AdvertisementPopupWindow(Activity context,String imgurl) {

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        contextView = inflater.inflate(R.layout.pop_advertisement, null);
        setContentView(contextView);
        ImageView iv = contextView.findViewById(R.id.iv);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               onclickListen.click();
            }
        });
        contextView.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        Glide.with(context).load(Path.img(imgurl))
                .into(iv);
        this.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
        this.setOutsideTouchable(false);
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(30000000);
        this.setBackgroundDrawable(dw);
        this.setAnimationStyle(R.style.my_dialog);
    }

    public void showDown(View view) {
        this.showAtLocation(view, Gravity.CENTER_HORIZONTAL, 0, 0);
    }
    onclick onclickListen;
    public interface  onclick{
        void click();
    }
}
